﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace MyWpfFramework.ViewModels
{
    public partial class PersonViewModel : ObservableRecipient
    {
        [ObservableProperty]
        [NotifyPropertyChangedRecipients]
        private string name;
        [ObservableProperty]
        [NotifyPropertyChangedRecipients]
        private string description;
        //注册
        public PersonViewModel()
        {
            Name = "";
            Description = "";

            WeakReferenceMessenger.Default.Register<ValueChangedMessage<DemoDataModel>, string>(this, "1",
                (_, message) => {
                    Name = message.Value.Name;
                    Description = message.Value.Remark;
                });
            IsActive = true;
        }
        //接收
        //public void Receive(ValueChangedMessage<DemoDataModel> message)
        //{
           
        //    Name = message.Value.Name;
        //    Description = message.Value.Remark;
        //}
        
        [RelayCommand]
        private void AddRow()
        {
            DemoDataModel demoDataModel = new DemoDataModel();
            demoDataModel.Name = Name;
            demoDataModel.Remark = Description;
            demoDataModel.IsSelected = false;
            demoDataModel.Index = 3;
            //发送
            WeakReferenceMessenger.Default.Send( new ValueChangedMessage<DemoDataModel>(demoDataModel) );
        }

      
    }
    record StringMessage(string message);
}
